package GameSrc;

import java.awt.*;
import java.util.Random;

public class Fish extends GameObject {
    private final int []arrWidth={300,45,55,73};

    private final int []arrHeight={106,44,28,30};

    private final int []arrScare = {5,8,3,3};

    private int scare;

    private int num=1;

    private final int speed=5;

    private boolean isExplosion = false;


    private final Random random = new Random();

    private int fish = random.nextInt(3);

    private final String head = "Game/img/fish";

    private final String middle = "/fish";

    private final String tail = ".png";

    private final String CATCH = "_catch_";


    public Fish() {
    }

    public Fish(int x, int y, GameWindow gameWindow) {
        super(80,80, x, y, "Game/img/fish1/fish1.png", gameWindow);
        setFishS();
    }

    public int getScare() {
        return scare;
    }

    public void setExplosion(boolean explosion) {
        isExplosion = explosion;
    }

    public void setFishS(){
        this.fish = random.nextInt(4);
        this.setWidth(arrWidth[fish]);
        this.setHeight(arrHeight[fish]);
        this.scare=arrScare[fish];
        this.fish+=1;
        String fishImg = head + fish + middle + num + tail;
        this.setImg(fishImg);
    }

    public void fishMove(){
        if (!isExplosion){
            int x = this.getX();
            this.setX(x-speed);
            this.renewalRec(this.getX(),this.getY(),this.getWidth(),this.getHeight());
            isOutOfBounds();
        }
    }

    public void isOutOfBounds(){
        if (this.getX()<-40){
            this.getGameWindow().removeFish.add(this);
        }
    }

    public void paintFish(Graphics g){
        if (!isExplosion){
            this.setImg(head+fish+middle+num+tail);
            g.drawImage(this.getImg(),this.getX(),this.getY(),null);
            num++;
            if (num==11){
                num=1;
            }
        } else if (isExplosion) {
            if (num>2){
                num=1;
            }
            this.setImg(head+fish+middle+CATCH+num+tail);
            g.drawImage(this.getImg(),this.getX(),this.getY(),null);
            if (num==1){
                num=2;
            } else if (num==2){
                num=1;
            }
        }

    }

}
